import 'package:flutter/material.dart';

import '../../tab_bookshelf/data.dart';
import '../../../../widgets/common_image.dart';
import './common_list_widgets.dart';

var titleStyle = TextStyle(fontSize: 18.0, fontWeight: FontWeight.w400);
var moreTitleStyle =
    TextStyle(fontSize: 16.0, fontWeight: FontWeight.w400, color: Colors.grey);

class CommonList extends StatelessWidget {
  final String title;
  final bool iconShow;
  final bool firstTitle;
  final IconData? suffix;
  const CommonList(this.title,
      {Key? key, this.iconShow = false, this.firstTitle = false, this.suffix})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 8.0),
      padding: EdgeInsets.all(2.0),
      child: Column(children: [
        Container(
          height: 10,
          color: Color(0xfff5f5f5),
        ),
        // 标题
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                if (iconShow && suffix != null)
                  Padding(
                    padding: EdgeInsets.only(right: 4.0),
                    child: Icon(
                      suffix,
                      size: 18.0,
                    ),
                  ),
                Text(
                  title,
                  style: titleStyle,
                )
              ],
            ),
            Text(
              '更多 >',
              style: moreTitleStyle,
            )
          ],
        ),
        // 第一个
        if (firstTitle)
          Row(children: [
            Container(
                margin: EdgeInsets.only(top: 8.0, bottom: 5.0, right: 5.0),
                width: 100.0,
                height: 120.0,
                child: CommonImage(bookInfoData[0].bookImgUrl!)),
            Expanded(
                child: Container(
              height: 120.0,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Text(
                    bookInfoData[0].title!,
                    style: TextStyle(color: Colors.black87, fontSize: 18.0),
                  ),
                  Text(
                    bookInfoData[0].desc!,
                    style:
                        TextStyle(color: Colors.grey.shade500, fontSize: 14.0),
                    maxLines: 2,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(bookInfoData[0].subTitle!),
                      Text(
                        '${bookInfoData[0].rating!}分',
                        style: TextStyle(color: Colors.amber),
                      ),
                    ],
                  )
                ],
              ),
            ))
          ]),
        // 列表
        Wrap(
          spacing: 8.0,
          children:
              bookInfoData.map((item) => CommonListWidgets(item)).toList(),
        ),
        Container(
          height: 60.0,
        )
      ]),
    );
  }
}
